package gui.panel;

import enums.PanelsEnum;
import j_util.Utiles;
import model.BundleExpressions;

import javax.swing.*;
import javax.swing.text.StyledDocument;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.ResourceBundle;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Panel que muestra toda la informacion acerca de teoria de logica clasica. En desuso, se considera su eliminacion;
 * @author Jose Martin Rozanec;
 * @deprecated;
 */
public class ClassicTheoryTabbedPanel extends JTabbedPane {
    private String firstTab;
    private Map<PanelsEnum, JPanel> panelsMap;

    public ClassicTheoryTabbedPanel() {
        buildPanels();
        setTabs();
    }

    private void setTabs() {
        Iterator<PanelsEnum> iterator = panelsMap.keySet().iterator();
        PanelsEnum panelsEnum;
        while (iterator.hasNext()) {
            panelsEnum = iterator.next();
//            addTab(PanelsEnum.getString(panelsEnum), panelsMap.get(panelsEnum));
        }
    }

    private void buildPanels() {
        int textAreaWidth = 100;
        panelsMap = new HashMap<PanelsEnum, JPanel>();
        StringBuffer stringBuffer = new StringBuffer();
        JPanel introduction = new JPanel();
        JTextArea introductionTextArea = new JTextArea();
        introductionTextArea.setEditable(false);
        HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
        StyleSheet styleSheet = new StyleSheet();
//        styleSheet.setBase();
//        htmlEditorKit.setStyleSheet();
        stringBuffer.append(ResourceBundle.getBundle("TheoryBundle").getString(BundleExpressions.INTRODUCCION_PRIMER_PARRAFO_CLASICA) + "\n ");
        stringBuffer.append(ResourceBundle.getBundle("TheoryBundle").getString(BundleExpressions.INTRODUCCION_SEGUNDO_PARRAFO_CLASICA) + "\n ");
        stringBuffer.append(ResourceBundle.getBundle("TheoryBundle").getString(BundleExpressions.INTRODUCCION_TERCER_PARRAFO_CLASICA) + "\n ");
        stringBuffer.append(ResourceBundle.getBundle("TheoryBundle").getString(BundleExpressions.INTRODUCCION_CUARTO_PARRAFO_CLASICA) + "\n ");
        introductionTextArea.setText(Utiles.formatString(stringBuffer.toString(), textAreaWidth));
        introductionTextArea.setFont(new java.awt.Font("Arial", 1, 12));
        introduction.add(introductionTextArea);
//        panelsMap.put(PanelsEnum.TEORIA_CLASICA_INTRODUCCION, introduction);

        stringBuffer = new StringBuffer();
        stringBuffer.append(ResourceBundle.getBundle("TheoryBundle").getString(BundleExpressions.INTRODUCCION_PRIMER_PARRAFO_CLASICA) + "\n ");
        stringBuffer.append(ResourceBundle.getBundle("TheoryBundle").getString(BundleExpressions.INTRODUCCION_SEGUNDO_PARRAFO_CLASICA) + "\n ");
        stringBuffer.append(ResourceBundle.getBundle("TheoryBundle").getString(BundleExpressions.INTRODUCCION_TERCER_PARRAFO_CLASICA) + "\n ");
        stringBuffer.append(ResourceBundle.getBundle("TheoryBundle").getString(BundleExpressions.INTRODUCCION_CUARTO_PARRAFO_CLASICA) + "\n ");


        StringBuffer htmlStringBuffer = new StringBuffer();
        try {
            URI relativePath = new URI("../html/clasica/introduccion.html");
            System.out.println("" + relativePath.getPath());
            BufferedReader in = new BufferedReader(new FileReader(relativePath.getPath()));
            String str;
            while ((str = in.readLine()) != null) {
                htmlStringBuffer.append(str);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Exception");//todo delete
        } catch (URISyntaxException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        System.out.println("" + htmlStringBuffer.toString());//todo delete
        JEditorPane editorPane = new JEditorPane("text/html", htmlStringBuffer.toString());
        StyledDocument styledDocument = new HTMLDocument();
        JTextPane textPane = new JTextPane();

//        JEditorPane editorPane = new JEditorPane("text/html","<head><base href=\"file:d:/\"></head>"+
//"<b>hola</b><br>" + "<i>adios</i><br>" +
//"<font face=\"arial\">fuente arial</font><br>" +
//"<font face=\"courier\">fuente courier</font><br>" +
//"<font size=\"24\">fuente grande</font><br>" +
//"<font color=\"red\">color rojo</font><br>");

//        editorPane.setText(
// +
//"<img src=\"viejo.gif\"></img>");
        editorPane.setEditable(false);
        addTab("nolly", editorPane);
    }
}
